package com.hwadee.ems.controller;

import java.util.List;
import java.util.stream.Collectors;

import jakarta.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hwadee.ems.domain.dto.Result;
import com.hwadee.ems.domain.po.Semester;
import com.hwadee.ems.domain.vo.SemesterVO;
import com.hwadee.ems.service.ISemesterService;

/**
 * <p>
 * 学期 前端控制器
 * </p>
 *
 * @author EnosElinsa
 * @since 2024/06/21
 */
@RestController
@RequestMapping("/semester")
public class SemesterController {

    @Resource
    private ISemesterService semesterService;

    @GetMapping("/list")
    public Result<List<SemesterVO>> list() {
        return Result.ok(
            semesterService.list()
                .stream()
                .map(SemesterVO::new)
                .collect(Collectors.toList())
        );
    }

    @GetMapping("/get_current")
    public Result<SemesterVO> getCurrent() {
        Semester currentSemester = semesterService.getOne(
            Wrappers.lambdaQuery(Semester.class)
                .eq(Semester::getIsCurrentSemester, 1)
        );
        return Result.ok(new SemesterVO(currentSemester));
    }

}
